package com.dbgs.insurance.insuredperson.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dbgs.insurance.insuredperson.R;
import com.dbgs.insurance.insuredperson.activity.apply.NoticeActivity;
import com.hss.base.BaseActivty;
import com.hss.base.util.StartActivityUtil;

import java.util.List;


/**
 * 服务适配器 Created by lzx on 15/7/13.
 */
public class GridHomeNavigationAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private Context context;
	private List<String> mDataList;

	int[] iconArr = {R.drawable.icon_news, R.drawable.icon_evaluate,
			R.drawable.icon_service,R.drawable.icon_member};

	public GridHomeNavigationAdapter(Context context, List<String> dataList) {
		this.context = context;
		this.mDataList = dataList;
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return iconArr == null ? 0:mDataList.size();
	}

	@Override
	public Object getItem(int position) {
		return mDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = null;
		if (null == convertView) {
			viewHolder = new ViewHolder();
			convertView = mInflater.inflate(
					R.layout.adapter_home_navigation, parent, false);
			viewHolder.icon = (ImageView) convertView
					.findViewById(R.id.iv_home_navigation_icon);
			viewHolder.title = (TextView) convertView
					.findViewById(R.id.tv_home_navigation_title);
			convertView.setTag(viewHolder);
			convertView.setId(position);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		if (position < mDataList.size()) {
			final String item = mDataList.get(position);
			if (item != null) {
				//获取原图片
				viewHolder.title.setText(item);
				viewHolder.icon.setImageResource(iconArr[position]);
				viewHolder.title.setTag(item);
				convertView.setOnClickListener(click);
			}
		}

		return convertView;
	}
	
	View.OnClickListener click = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()){
				case 0:

					break;
				case 1:
					StartActivityUtil.startActivity(NoticeActivity.class,context);
					break;
				case 2:
					break;
				case 3:
					break;
			}

		}
	};

	private  class ViewHolder {
		ImageView icon;
		TextView title;
	}

}
